package com.example.canteen.controller;
import com.example.canteen.domain.Products;
import com.example.canteen.domain.Suppliers;
import com.example.canteen.service.ProductsService;
import com.example.canteen.service.SuppliersService;
import com.example.canteen.util.AjaxResult;
import com.example.canteen.util.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController

@RequestMapping("/products")
@Api(tags = "商品管理(0304 高凯)")
@Anonymous
public class ProductsController {
    @Autowired
    private ProductsService service;

//    selectAllProducts
    @GetMapping("/getProductsListAll")
    @ApiOperation(value = "获取所有商品列表")
//    selectAllProducts
    public AjaxResult getProductsListAll() {
        System.out.println(service.selectAllProducts());
        return AjaxResult.success(service.selectAllProducts());
    };

    @ApiOperation(value = "根据id查询商品信息")
    @GetMapping("/getProductsById/{productID}")
    public AjaxResult getProductsById(@PathVariable int productID) {
        System.out.println(service.selectProductsById(productID));
        return AjaxResult.success(service.selectProductsById(productID));
    }
    @ApiOperation(value = "根据商品名查询商品信息")
    @GetMapping("/getProductsByName/{productName}")
    public AjaxResult getProductsByName(@PathVariable String productName) {
        System.out.println(service.selectProductsByName(productName));
        return AjaxResult.success(service.selectProductsByName(productName));
    }

    @PostMapping("/insertProducts")
    @ApiOperation(value = "新增商品")
    public AjaxResult addSuppliers(@RequestBody Products products) {
        return AjaxResult.success(service.insertProducts(products));
    }
    @PutMapping("/UpdateProducts")
    @ApiOperation(value = "修改商品类别")
    public AjaxResult UpdateProducts(@RequestBody Products products){
        return AjaxResult.success(service.updateProducts(products));
    }
    @DeleteMapping("/DeleteSuppliers")
    @ApiOperation(value = "删除商品")
    public AjaxResult DeleteProducts(int id) {
        return AjaxResult.success(service.deleteProductsByID(id));
    }
}
